//
//  ProfileSercurityViewController.swift
//  App_Profile
//
//  Created by 蒋晨成 on 2022/2/11.
//

import Adaptor
import App_Common
import Route
import RxCocoa
import RxSwift
import SnapKit
import Toast
import UICore
import UIKit

class ProfileSercurityViewController: ViewController {
    lazy var listContentView: RYCollectionContentView = {
        let collectionViewLayout = UICollectionViewFlowLayout()
        collectionViewLayout.scrollDirection = .vertical
        collectionViewLayout.headerReferenceSize = CGSize(width: 300, height: 20)
        let listContentView = RYCollectionContentView(layout: collectionViewLayout)
        listContentView.backgroundColor = Adaptor.Profile.background
        listContentView.alwaysBounceVertical = true
        return listContentView
    }()
}

// MARK: - Override

extension ProfileSercurityViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNav()
        setup()
        bindData()
    }
}

private extension ProfileSercurityViewController {
    func setupNav() {
        if (navigationController?.viewControllers.count ?? 0) > 1 {
            let backImage = ProfileModular.image(named: "Common.Nav.Action.Back")
            addDefaultLeftBarButtonItem(image: backImage)
        }
        setNavigationBarTintColor(tintColor: Adaptor.Profile.titleColor)
        navigationItem.title = ProfileModular.localizedString(key: "Profile.Userinfo.Security")
    }

    func setup() {
        view.backgroundColor = Adaptor.Profile.background

        listContentView.x.add(to: view).snp.makeConstraints {
            $0.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            $0.leading.trailing.bottom.equalToSuperview()
        }
    }

    func bindData() {
        let logoffCellModel = RYTitleCellModel(title: ProfileModular.localizedString(key: "Profile.Secruity.Logoff")) { [self] _ in
            self.view.makeToastActivity(.center)
            Router.push(pattern: "security/logoff")
        }
        let section0 = [logoffCellModel]
        listContentView.ryDataList.append(section0)
    }
}

// MARK: - Routable

extension ProfileSercurityViewController: Routable {
    static func initialize(values _: [String: Any]) -> ViewController? {
        ProfileSercurityViewController(nibName: nil, bundle: nil)
    }

    static var routePattern = "profile/edit/security"

    static let description: String = "Profile Security Router"
}
